package com.lin.zoo.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class DataBase {


    //连接数据库
    public static Connection getCon()throws SQLException,ClassNotFoundException{
        String dbURL = "jdbc:mysql://localhost:3306/zoo?characterEncoding=UTF-8";//sqlURL
        String dbUser = "root";//root  -u
        String dbPassword = "0411,lzh";//password   -p
        String jdbcName = "com.mysql.cj.jdbc.Driver";
        Class.forName(jdbcName);
        return DriverManager.getConnection(dbURL, dbUser, dbPassword);
    }

    //关闭数据库连接
    public static void close(PreparedStatement st, Connection con)throws SQLException{
        if(st!=null){
            st.close();
            if(con!=null){
                con.close();
            }
        }
    }
}
